package com.zj.leetcode.medium.dynamicProgramming;

import java.util.Arrays;

/**
 * @program: algorithm
 * @description:
 * 打家劫舍 II
 * 213 house-robber-ii
 * @author: Zhang Bo
 * @create: 2022-01-14 17:05
 **/
public class HouseRobberIi{
    public static void main(String[] args) {
        Solution solution = new HouseRobberIi().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int rob(int[] nums) {
            return Math.max(
                    myRob(Arrays.copyOfRange(nums, 0, nums.length - 1)),
                    myRob(Arrays.copyOfRange(nums, 1, nums.length)));
        }

        public int myRob(int[] nums) {
            System.out.println(nums.length);
            if(nums.length < 1){
                return 0;
            }
            if(nums.length == 1){
                return nums[0];
            }
            int n = nums.length;
            int[] dp = new int[n + 1];
            dp[0] = 0;
            dp[1] = nums[0];
            for (int i = 2; i <= n; i++) {
                dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i - 1]);
            }
            return dp[n];
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
